package 笔试.微众移行.thr;

import org.junit.Test;

public class Main {
    public static void main(String[] args) {
        int[][] g ={{1,2},{-1,3}};
        int X=2,Y=2;
        int[][] fx = {
                {1,0}, //k
                {-1,0}, //j
                {0,-1},//h
                {0,1}//l
        };

        int i=0,j=0;
        int n=2,m=2;
        String s = "kjljk";
        char fafx=s.charAt(0);
        int sum=0;
        for (int k = 0; k < s.length(); k++) {
            char cfx=s.charAt(k);
            //gaifx
            if(fafx!=cfx && k!=0)sum+=X;
            //dieda
            fafx=cfx;

            //zhangaiwu
            //上-下+
            int ci=0,cj=0;
            if(cfx=='k'){
                ci=i-1;cj=j;
            }
            else if(cfx=='j'){
                ci=i+1;cj=j;
            }
            else if(cfx=='h'){
                ci=i;cj=j-1;
            }
            else if(cfx=='l'){
                ci=i;cj=j+1;
            }

            if(ci<0 || ci>=n || cj<0 || cj>=m || g[ci][cj]==-1 ){
                sum+=Y;
                //不迭代ij
            }else {
                sum+=Math.max(g[i][j],g[ci][cj]);
                i=ci;j=cj;
            }
            System.out.println(i+","+j);

        }
        System.out.println(sum);
    }
}

/*

    int[][] g;
    int[][] vis;
    int n,m;

    int resMaxS = 0;
    public int maxAreaOfIsland(int[][] grid) {
        g=grid;
        n=g.length; m=g[0].length;
        vis = new int[g.length][g[0].length];

        for (int i = 0; i < g.length; i++) {
            for (int j = 0; j < g[0].length; j++) {
                if(g[i][j] == 1){
                    int x=i,y=j;
                    pre(x,y);
                    quanjuS = 0;
                }
            }
        }
        return resMaxS;
    }

    int[][] fx = {
            {1,0}, //k
            {-1,0}, //j
            {0,-1},//h
            {0,1}//l
    };

    int quanjuS = 0;

    private void pre(int i, int j) {

        quanjuS++;
        resMaxS = Math.max(quanjuS, resMaxS);
        vis[i][j] = 1;

        for (int k = 0; k < fx.length; k++) {
            int x = i+fx[k][0], y = j+fx[k][1];
            if(x<0 || x>=n || y<0 || y>=m || g[x][y]==0 || vis[x][y]==1) {
                continue;
            }
            pre(x, y);
        }
    }
}
 */
